<?php
class Member extends CI_Controller {

	public function index(){
		$this->login();
	}
	
	//登入
	public function login(){
		//$menu = show_menu();
		//$this->load->view('menu', $menu);
		$this->load->helper(array('form', 'url'));
		//$this->load->library('form_validation');
		//$this->form_validation->set_rules('username', '帳號', 'required');
		//$this->form_validation->set_rules('password', '密碼', 'required');
		if($this->form_validation->run()==FALSE){
			$this->load->view('menu');
		}else{
			$this->load->view('welcome_message');
		}
	}
	
	public function isLogin(){
		$username = $this->input->post('username');
		$password = $this->input->post('password');
		$remember = $this->input->post('remember');
		//$this->load->library('ion_auth');
		$isLogin = $this->ion_auth->login($username, $password, $remember);
		//if(!$isLogin){
		if (!$this->ion_auth->logged_in()){
			$this->form_validation->set_message('password', 'The %s field can not be the word "test"');
		}
		return FALSE;
	}
	
		
	function logout($backUrl=""){
		//log the user out
		$logout = $this->ion_auth->logout();
		//redirect them to the login page
		$this->session->set_flashdata('message', $this->ion_auth->messages());
		redirect(urldecode(urldecode($backUrl)), 'refresh');
	}
	
	private function genMenu(){
		$obj = &get_instance();
		$obj->load->helper('url');
		$menu = anchor("start/hello/fred","Say hello to Fred |");
		$menu .= anchor("start/hello/bert","Say hello to Bert |");
		$menu .= anchor("start/another_function","Do something else |");
		return $menu;
	}
}
?>